home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / backup / kbackup-.000 / KBackup-1.2.7.tar / KBackup / kbackup < prev    next >
Text File  |  1996-03-27  |  53KB  |  2,115 lines

  1. #!/bin/sh
  2. #
  3. #    /home/kbackup/.CVSROOT/KBackup/kbackup,v 1.34 1996/03/27 20:03:27 kbackup Exp
  4. #    (C) 1995, 1996 by Karsten Ballⁿder 
  5. #                         (karsten.ballⁿder@stud.uni-karlsruhe.de)
  6. #
  7. #
  8.  
  9. #
  10. #    set default values for Variables
  11. #
  12.  
  13. VERSION="1.2.7"
  14.  
  15. echo "Initialising, phase 1..."
  16.  
  17. SED=sed
  18. FGREP=fgrep
  19. GREP=grep
  20. TAR=tar
  21. AFIO=afio
  22. DD=dd
  23. DIALOG=dialog
  24. MAIL=mail
  25. WC=/usr/bin/wc
  26. MULTIBUF=multibuf
  27. STD_COMPRESS=gzip        # for logfiles, if no compression set
  28.  
  29. AFIO_PROGRAMS="gzip sh afio"    # to rescue them from being overwritten,
  30.                 # nasty bug in afio 2.4.1
  31.  
  32. PATHFILE=paths
  33. CHECKPRGS=checkprogs
  34. if [ "$SRCDIR" = "" ]
  35. then
  36.     SRCDIR=/etc/KBackup
  37. fi
  38.  
  39. RESTORE_SRC=restore_src
  40. Restore_src_loaded=NO
  41. BACKUP_SRC=backup_src
  42. Backup_src_loaded=NO
  43. READDATA_SRC=read_data_src
  44. ReadData_src_loaded=NO
  45. VERIFY_SRC=verify_src
  46. Verify_src_loaded=NO
  47. WriteData_src_loaded=NO
  48. WRITEDATA_SRC=write_data_src
  49. Blockdev_src_loaded=NO
  50. BLOCKDEV_SRC=blockdev_src
  51. AUTODETECT_SRC=autodetect_src
  52. Autodetect_src_loaded=NO
  53. DIALOG_SRC=dialog
  54.  
  55. Configuration_changed=NO
  56.  
  57. SOURCE_FILES="$RESTORE_SRC $BACKUP_SRC $BLOCKDEV_SRC $VERIFY_SRC $AUTODETECT_SRC $READDATA_SRC $WRITEDATA_SRC subroutines checkprogs paths"
  58.  
  59. DIALOGTITLE="KBackup Version $VERSION            Copyright (C) 1995, 1996 by Karsten Ballueder"
  60. MAILADDRESS="karsten.ballueder@stud.uni-karlsruhe.de"
  61.  
  62. FILESPERARCHIVE_STD=3
  63. FILESPERARCHIVE="$FILESPERARCHIVE_STD"
  64.             # compression method, cont-dir, archive
  65.             #   +1 for every multibuf end marker when using
  66.             # sequence information ==> 5
  67.  
  68. BLOCKDEV_HEADER="KBackup-Header"
  69. BLOCKDEV_DIRECTORY="Directory"
  70. BLOCKDEV_ARCHIVE="Archive"
  71.  
  72. KBACKDIRDEFAULT=.KBackup
  73. KBACKRCDEFAULT=.kbackrc
  74.  
  75. STD_TAROPT_BACK="--sparse "
  76. STD_TAROPT_REST="--sparse "
  77. STD_AFIOOPT_BACK=""
  78. STD_AFIOOPT_REST=""
  79. STD_MULTIBUF_OPT=""
  80.  
  81. # MultiBuf Commands for BLOCKDEV: command1, command2, retry-command:
  82.  
  83. MBUF_BLOCKDEV_WCMD1="umount \$MOUNTPOINT && dialog --title 'KBackup: MultiBuf' --msgbox '\nPlease insert next volume...' 7 34 && clear"
  84. MBUF_BLOCKDEV_WCMD2="mount -t \$blockdev_fs_type \"\$device\" \$MOUNTPOINT"
  85. MBUF_BLOCKDEV_RCMD1="umount \$MOUNTPOINT && dialog --title 'KBackup: MultiBuf' --msgbox '\nPlease insert next volume...' 7 34 && clear"
  86. MBUF_BLOCKDEV_RCMD2="mount -t \$blockdev_fs_type \"\$device\" \$MOUNTPOINT"
  87. MBUF_BLOCKDEV_RCMDR="umount \$MOUNTPOINT && dialog --title 'KBackup: MultiBuf' --yesno '\nDetected wrong sequence number!\nRetry with another volume?' 7 38 && mount -t \$blockdev_fs_type \"\$device\" \$MOUNTPOINT"
  88.  
  89. export blockdev_fs_type device MOUNTPOINT
  90.  
  91. # Multibuf Commands for ttymode:
  92.  
  93. MBUF_BLOCKDEV_WCMD1_TTY="umount \$MOUNTPOINT && echo -ne '\nPlease insert next volume and press ENTER...' && read "
  94. MBUF_BLOCKDEV_WCMD2_TTY="mount -t \$blockdev_fs_type \"\$device\" \$MOUNTPOINT"
  95. MBUF_BLOCKDEV_RCMD1_TTY="umount \$MOUNTPOINT && echo -ne '\nPlease insert next volume and press ENTER...'  && read "
  96. MBUF_BLOCKDEV_RCMD2_TTY="mount -t \$blockdev_fs_type \"\$device\" \$MOUNTPOINT"
  97. MBUF_BLOCKDEV_RCMDR_TTY="umount \$MOUNTPOINT && echo -ne '\n\aERROR: Detected wrong sequence number!\nEnter Y to retry with another volume. '  && read tmp
  98. && test "$tmp" = "Y" -o "$tmp" = "y"  && mount -t \$blockdev_fs_type \"\$device\" \$MOUNTPOINT"
  99.  
  100.  
  101.  
  102. FIND_STD_OPTS="-noleaf -depth"    # to avoid endless errors on non unix fs
  103.                 # -depth to avoid errors with unreadable dirs
  104.                 # see cpio(1) man page for details
  105.  
  106. kbackdir="$HOME/$KBACKDIRDEFAULT"
  107. MOUNTPOINT="$kbackdir/mnt"
  108. parent=/
  109. local=NO
  110. incremental=NO
  111. specifiedfilesonly=NO
  112. datestamp=`date +"%D %T"`
  113. directoriesonly=YES
  114. findxpertmode=NO
  115. findxpertflags=-print
  116. compression=GZIP        #valid: GZIP, PGP, NONE, COMPRESS
  117. compress_options=-1
  118. decompress_options=-d
  119. archive_format=AFIO        #valid: TAR 
  120. verify_archive=YES
  121. pgpkey=root
  122. configname=Default
  123. ddbufsize=4096k
  124. double_buffering=YES
  125. device=/dev/tape
  126. resetdevice=/dev/tape-reset
  127. device_type=TAPE        # valid: TAPE, FLOPPY, BLOCKDEV
  128. blockdev_fs_type=ext2
  129. blockdev_mkfs="mkfs -t ext2 -c"
  130. floppy_format="1722/1440"
  131. manualedit=NO
  132. followtarops=YES
  133. scheduled=NO
  134. schedulename=.---schedule---
  135. scheduletime="???"
  136. oldconfigname="$configname"
  137. scheduled_only_once=YES
  138. use_multibuf=YES
  139. multibuf_nblocks=100
  140. multibuf_blksize=1024
  141. multibuf_seq_info=YES
  142. multibuf_cmd1=DEFAULT
  143. multibuf_cmd2=DEFAULT
  144. restore_write_log=YES
  145. CreateReport=NO
  146. ReportCommand="lpr"
  147. AutoRewind=YES
  148. protect_newer=YES
  149. use_patterns=NO
  150. manual_command="dialog --textbox /usr/doc/KBackup/manual.asc 24 77"
  151. afio_user_opts="-T 3k"
  152. tar_user_opts=
  153.  
  154. TMP=/tmp
  155. realTMP=$TMP
  156. TMP=$TMP/kbtmp$$
  157.  
  158. DATEFILE=kbdate$$
  159. TMPFILE=kbtmp$$
  160. TMPFILE2=kbtmpB$$
  161. BINDIR=kbfakegzip$$
  162. COMPRESSFILE=kbcompress$$
  163. DIALOGFILE=kbdialog$$
  164. DIRLISTFILE=kbdirlist$$
  165. TARLOGFILE=kbtarlog$$
  166. TARLISTFILE=kbtarlist$$
  167. MAILFILE=kbmail$$
  168. EXCLUDE=kbexclude$$
  169. PIPEFILE=kbpipe$$
  170. MSGFILE=kbinfo$$
  171. ERRFILE=kbstderr$$
  172. FINDFILE=kbfind$$
  173. STDERR="$TMP/$ERRFILE"
  174. MBUF_SCRIPT1=kbmbcmd1$$
  175. MBUF_SCRIPT2=kbmbcmd2$$
  176. MBUF_SCRIPTR=kbmbcmdr$$
  177. MVOLFLAG=kbmvolflag$$
  178. REPORTFILE=kbreport$$
  179. PHRASEFILE=.kbphr$$
  180.  
  181. TMPFILES="$TMP/$TMPFILE $TMP/$DIRLISTFILE $TMP/$DIALOGFILE \
  182.     $TMP/$TARLOGFILE $TMP/$TARLISTFILE $TMP/$MSGFILE $TMP/$PIPEFILE\
  183.     $TMP/$COMPRESSFILE $TMP/$TMPFILE2 $TMP/$BINDIR $TMP/$EXCLUDE $TMP/$ERRFILE\
  184.     $TMP/$MBUF_SCRIPT1 $TMP/$MBUF_SCRIPT2 $TMP/$MBUF_SCRIPTR $TMP/$FINDFILE\
  185.     $TMP/$REPORTFILE $TMP/$MAILFILE $TMP/$MVOLFLAG $TMP/$PHRASEFILE $TMP/$DATEFILE"
  186.  
  187. # set new temporary directory
  188. changeTMP()
  189. {
  190.     if [ "$TMP" != "$realTMP" ] ; then
  191.         rm -rf $TMP
  192.         rmdir $TMP 2>/dev/null
  193.     fi
  194.     
  195.     realTMP="$1"
  196.     TMP="$1/kbtmp$$"
  197.  
  198.     STDERR="$TMP/$ERRFILE"
  199.     TMPFILES="$TMP/$TMPFILE $TMP/$DIRLISTFILE $TMP/$DIALOGFILE \
  200.     $TMP/$TARLOGFILE $TMP/$TARLISTFILE $TMP/$MSGFILE $TMP/$PIPEFILE\
  201.     $TMP/$COMPRESSFILE $TMP/$TMPFILE2 $TMP/$BINDIR $TMP/$EXCLUDE $TMP/$ERRFILE\
  202.     $TMP/$MBUF_SCRIPT1 $TMP/$MBUF_SCRIPT2 $TMP/$MBUF_SCRIPTR $TMP/$FINDFILE\
  203.     $TMP/$REPORTFILE $TMP/$MAILFILE $TMP/$MVOLFLAG $TMP/$PHRASEFILE"
  204. }
  205.  
  206.  
  207. check_for_source_files()
  208. {
  209.     echo -e "\tchecking for required source files in $SRCDIR..."
  210.     for i in $SOURCE_FILES
  211.     do
  212.         test -r "$SRCDIR/$i"
  213.         if [ $? != 0 ]
  214.         then
  215.             echo -e "\t\aFATAL ERROR:"$i" not found!"
  216.             exit 1
  217.         else
  218.             echo -en " $i"
  219.         fi
  220.     done
  221.     echo 
  222. }
  223.  
  224. Init()
  225. {
  226.     check_for_source_files
  227.     
  228.     echo "Initialising, phase 2..."
  229.  
  230.     if [ ! -d $TMP ] ; then
  231.         mkdir $TMP
  232.         if [ $? != 0 ] ; then
  233.             echo -e "\t\aCannot make $TMP!"
  234.             exit 1
  235.         fi
  236.     fi
  237.     
  238.  
  239.  
  240.     if [ -r "$HOME/$KBACKRCDEFAULT" ] ; then
  241.         echo -e "\tReading $HOME/$KBACKRCDEFAULT..."
  242.         . "$HOME/$KBACKRCDEFAULT"
  243.     fi
  244.     
  245.     if [ -r "$SRCDIR/$PATHFILE" ] ; then
  246.         echo -e "\tReading $SRCDIR/$PATHFILE..."
  247.         . "$SRCDIR/$PATHFILE"
  248.         . "$SRCDIR/$CHECKPRGS"
  249.         DIALOG_SRC_FILE=""
  250.         check_progs
  251.         report_missing
  252.         if [ $HasDIALOG = NO -o "$TTYMODE" = YES ]
  253.         then
  254.             echo -e "\tLoading dialog-emulation script..."
  255.             . "$SRCDIR/$DIALOG_SRC"
  256.         fi
  257.         MYDIALOGTITLE="$DIALOGTITLE"
  258.         . "$SRCDIR/subroutines"
  259.         check_error
  260.     fi
  261.  
  262.     if [ ! -d "$kbackdir" ] ; then
  263.         echo -e "\tCreating $kbackdir..."
  264.         mkdir "$kbackdir"
  265.         check_error
  266.     fi
  267.  
  268.     MOUNTPOINT="$kbackdir/mnt"
  269.     if [ ! -d "$MOUNTPOINT" ] ; then
  270.         echo -e "\tCreating $MOUNTPOINT..."
  271.         mkdir "$MOUNTPOINT"
  272.         check_error
  273.     fi
  274.     
  275.     if [ ! -d "$datadir" ] ; then
  276.         echo -e "\tCreating $datadir..."
  277.         mkdir "$datadir"
  278.         check_error
  279.     fi
  280.     
  281.     if [ ! -d "$datadir/$configname" ] ; then
  282.         echo -e "\tCreating $datadir/$configname..."
  283.         mkdir "$datadir/$configname"
  284.         check_error
  285.     fi
  286.  
  287.     if [ -r "$datadir/$configname/Config" ] ; then
  288.         echo -e "\tReading $datadir/$configname/Config..."
  289.         . "$datadir/$configname/Config"
  290.         check_error
  291.         changeTMP "$TMP"
  292.     fi
  293.  
  294.     if [ -r "$datadir/$configname/DateStamp" -a -s $kbackdir/$configname/DateStamp ]
  295.     then 
  296.         datestamp=`cat $datadir/$configname/DateStamp`
  297.         check_error
  298.     fi
  299.  
  300.     touch "$datadir/$configname/Include_Files" 2>/dev/null
  301.     touch "$datadir/$configname/Exclude_Files" 2>/dev/null
  302.     touch "$datadir/$configname/Include_Patterns" 2>/dev/null
  303.     touch "$datadir/$configname/Exclude_Patterns" 2>/dev/null
  304.  
  305.     if [ ! -d "$MOUNTPOINT" ] ; then
  306.         echo -e "\tCreating mountpoint $MOUNTPOINT..."
  307.         mkdir "$MOUNTPOINT"
  308.         check_error
  309.     fi
  310.     rm -f $MOUNTPOINT/* 2>/dev/null
  311.     
  312.     if [ "$EDITOR" = "" ] ; then
  313.         EDITOR=vi
  314.     fi
  315.     save_options    # to initialise old_* variables
  316. }
  317.  
  318. Calculate_MaxArcLen()
  319. {
  320.     # round to kilobytes and add 100Kb for safety:
  321.     set -f
  322.     bytes_written=`expr \( \( $bytes_written / 1024 \) + 100 \) * 1024`
  323.     set +f
  324.  
  325.     maxarchivelength=`expr $tapelength - $bytes_written`
  326. }
  327.  
  328.  
  329. Backup()
  330. {
  331.     if [ "$Backup_src_loaded" != "YES" ]
  332.     then
  333.         . "$SRCDIR/$BACKUP_SRC"
  334.     fi
  335.     Backup_II
  336. }
  337.  
  338. Get_BackupSize()
  339. {
  340.     InfoBox "Creating list of files..."
  341.     
  342.     build_find_arguments
  343.  
  344.     echo >$TMP/$TMPFILE2
  345.     cd "$parent"
  346.     set -f
  347.     echo find . "$findargs" -fprintf $TMP/$TMPFILE2 \"%k\\n\" >$TMP/$FINDFILE
  348.     . "$TMP/$FINDFILE" 2>/dev/null
  349.     set +f
  350.  
  351.     InfoBox "Adding file sizes..."
  352.  
  353.     echo 0 >$TMP/$TMPFILE
  354.     sed '1,$ s/^\(.*\)$/ + \1/g' <$TMP/$TMPFILE2 >>$TMP/$TMPFILE
  355.     size=`expr \`cat $TMP/$TMPFILE\``
  356.  
  357.     MsgBox \
  358. "Total backup size before compression
  359. is $size KiloBytes ( = `expr \( $size + 512 \) / 1024` MB).
  360.  
  361. If using compression you will need
  362. roughly half that space on your 
  363. backup media."
  364. }
  365.  
  366.  
  367. View_Logfile()
  368. {
  369.     cd $datadir
  370.     find * -type d -prune -printf "%f %Tx\n" | sort >$TMP/$TMPFILE
  371.  
  372.     $DIALOG   --menu "Choose a configuration:" 20 60 `$WC -l <$TMP/$TMPFILE` \
  373.         `cat $TMP/$TMPFILE` 2>$TMP/$DIALOGFILE
  374.     if [ $? = 0 ]
  375.     then
  376.         dir=`cat $TMP/$DIALOGFILE`
  377.         find "$datadir/$dir" -type f -prune -printf "%f %Tx\n" |\
  378.         $FGREP "Log" | sort >$TMP/$TMPFILE
  379.         $DIALOG   --menu "Choose a logfile:" 20 60 `$WC -l <$TMP/$TMPFILE` \
  380.             `cat $TMP/$TMPFILE` 2>$TMP/$DIALOGFILE
  381.         if [ $? = 0 ]
  382.         then
  383.             old_compression="$compression"
  384.             uncompress_logfile "$datadir/$dir/`cat $TMP/$DIALOGFILE`" 3<$TMP/$PHRASEFILE
  385.             $DIALOG   --title "`cat $TMP/$DIALOGFILE`" --textbox $TMP/$TMPFILE 23 75 2>/dev/null
  386.             
  387.             compression="$old_compression"
  388.         fi
  389.     fi
  390. }
  391.  
  392.  
  393. Delete_Logfile()
  394. {
  395.     cd "$datadir"
  396.     find * -type d -prune -printf "%f %Tx\n" | sort >$TMP/$TMPFILE
  397.     $DIALOG   --menu "Choose a configuration:" 20 60 `$WC -l <$TMP/$TMPFILE` \
  398.         `cat $TMP/$TMPFILE` 2>$TMP/$DIALOGFILE
  399.     if [ $? = 0 ]
  400.     then
  401.         dir=`cat $TMP/$DIALOGFILE`
  402.         cd "$dir"
  403.         find * -type f -prune -printf "%f %Tx\n" |\
  404.         $FGREP "Log" | sort >$TMP/$TMPFILE
  405.         $DIALOG   --menu "Choose a logfile:" 20 60 `$WC -l <$TMP/$TMPFILE` \
  406.             `cat $TMP/$TMPFILE` 2>$TMP/$DIALOGFILE
  407.         if [ $? = 0 ]
  408.         then
  409.             filename=`cat $TMP/$DIALOGFILE`
  410.             if [ -f "$filename" ]
  411.             then
  412.                 $DIALOG --title " Please confirm: " --yesno \
  413.                 "\nDelete "$datadir/$dir/$filename" ?" 7 60
  414.                 if [ $? = 0 ]
  415.                 then
  416.                     rm "$filename"
  417.                 fi
  418.             fi
  419.         else
  420.             MsgBox "No logfiles found."
  421.         fi
  422.     fi
  423. }
  424.  
  425. View_Contents()
  426. {    
  427.     backup_version="???"
  428.     backup_date="???"
  429.     backup_compression="???"
  430.     backup_type="???"
  431.     backup_files_per_archive="???"
  432.     backup_archive_format="???"
  433.     backup_donly="???"
  434.     backup_use_multibuf="???"
  435.     backup_multibuf_blksize="???"
  436.     backup_multibuf_nblocks="???"
  437.     backup_multibuf_seq_info="???"
  438.     backup_parent="???"
  439.  
  440.     if [ "$ReadData_src_loaded" != "YES" ]
  441.     then
  442.         . "$SRCDIR/$READDATA_SRC" 2>$STDERR || ( check_error ; return )
  443.     fi
  444.     if [ "$Blockdev_src_loaded" != "YES" ]
  445.     then
  446.         . "$SRCDIR/$BLOCKDEV_SRC" 2>$STDERR || ( check_error ; return )
  447.     fi
  448.     
  449.     insert_media
  450.     if [ $? != 0 ]
  451.     then
  452.         return
  453.     fi
  454.  
  455.     auto_rewind
  456.  
  457.     if [ "$device_type" = "TAPE" -o "$device_type" = "BLOCKDEV" ]
  458.     then
  459.         if [ -f "$device" ] ; then # file => do extra directory file
  460.             dirfile="$device.dir"
  461.         else
  462.             if [ "$device_type" = "BLOCKDEV" ]
  463.             then
  464.                 dirfile="$MOUNTPOINT/$BLOCKDEV_DIRECTORY"
  465.                 header="$MOUNTPOINT/$BLOCKDEV_HEADER"
  466.                 archive="$MOUNTPOINT/$BLOCKDEV_ARCHIVE"
  467.                 get_blockdev READ
  468.             else
  469.                 dirfile="$device"
  470.                 header="$device"
  471.                 archive="$device"
  472.             fi
  473.  
  474.             InfoBox "Reading header..." 
  475.             read_data -raw "$header" >$TMP/$TMPFILE 2>$STDERR
  476.             check_error -dev
  477.             if [ $? != 0 ]
  478.             then
  479.                 release_blockdev
  480.                 return
  481.             else
  482.                 if read firstline < $TMP/$TMPFILE && [ "$firstline" = "#KBackup" ]
  483.                 then
  484.                     . $TMP/$TMPFILE && $DIALOG   --title "Archive header information" --msgbox "\n\
  485. Archive created by KBackup Version: $backup_version\n\
  486.   files per archive: .............. $backup_filesperarchive\n\
  487. Creation date: .................... $backup_date\n\
  488. Backup type: ...................... $backup_type\n\
  489. Archive format: ................... $backup_archive_format\n\
  490. Compression method: ............... $backup_compression\n\
  491. Directories-only flag: ............ $backup_donly\n\
  492.   using Multibuf: ................. $backup_use_multibuf\n\
  493.   Multibuf blocksize: ............. $backup_multibuf_blksize\n\
  494.   Multibuf number of blocks: ...... $backup_multibuf_nblocks\n\
  495. \n\
  496. Parent Directory of Backup: ....... $backup_parent\n" 20 75 
  497.         
  498.                 else
  499.                     ErrorBox "File is not a valid KBackup Archive Header."
  500.                     release_blockdev
  501.                     return
  502.                 fi
  503.             fi
  504.         fi
  505.         if [ "$compression" = "PGP" ]
  506.         then
  507.             GetPGPPASS
  508.         fi
  509.         set_compress
  510.     
  511.         InfoBox "Reading directory..." 
  512.         ( read_data "$dirfile" | $uncompress ) >$TMP/$TMPFILE 2>$STDERR 3<$TMP/$PHRASEFILE
  513.         if check_compress_success
  514.         then
  515.             $DIALOG   --title "Archive contents directory" --textbox $TMP/$TMPFILE 23 75
  516.         else
  517.             beep
  518.             ErrorBox "Cannot read contents directory.
  519. Maybe tape at wrong position?" 8 40
  520.         fi    
  521.     else        # device is floppy
  522.         if [ "$archive_format" = "TAR" ]
  523.         then
  524.             $TAR -tvf "$device" 2>&1 >$TMP/$TMPFILE
  525.         else
  526.             blocks=`echo $floppy_format|$SED '1,$ s/\(.*\)\/.*/\1k/g' `
  527.             $AFIO -tlvF -s $blocks "$device" 2>&1 >$TMP/$TMPFILE
  528.         fi
  529.         if [ $? -eq 0 ]
  530.         then
  531.             $DIALOG   --title "Archive contents directory" --textbox $TMP/$TMPFILE 23 75
  532.         else
  533.             ErrorBox "Reading of archive contents failed!"
  534.         fi
  535.     fi
  536.     release_blockdev
  537.     clear_PGP
  538. }    
  539.  
  540.  
  541. Restore()
  542. {
  543.     if [ "$Restore_src_loaded" != "YES" ]
  544.     then
  545.         . "$SRCDIR/$RESTORE_SRC"
  546.     fi
  547.     Restore_II
  548. }
  549.  
  550. schedule()
  551. {
  552.     schedulename=.--scheduled--$$
  553.     oldconfigname="$configname"
  554.     configname="$schedulename"
  555.     save_config
  556.     configname="$oldconfigname"
  557.     echo oldconfigname="\"$configname\"" >>$datadir/$schedulename/Config
  558.     echo scheduled=YES >>"$datadir/$schedulename/Config"
  559. }
  560.  
  561. unschedule()
  562. {
  563.     configname="$oldconfigname"
  564.     if [ "$scheduled_only_once" = "YES" ]
  565.     then
  566.         rm -rf "$datadir/$schedulename"
  567.     fi
  568.     save_config
  569. }
  570.  
  571. enter_time()
  572. {
  573.     $DIALOG   --inputbox "Please enter time and date in at(1) format:\n\
  574. Current time and date is: `date`." 9 75 2>$TMP/$DIALOGFILE 
  575.     if [ $? = 0 ] && test -n "`cat $TMP/$DIALOGFILE`"
  576.     then
  577.         scheduletime=`cat $TMP/$DIALOGFILE`
  578.     fi
  579. }
  580.  
  581. do_schedule()
  582. {
  583.     while : ; do
  584.     $DIALOG   --title "Scheduling" --menu "Please choose:" 12 38 5 \
  585.         T    "Set date and time" \
  586.         B    "Schedule a backup" \
  587.         R    "Schedule a restore" \
  588.         O    "Toggle Once Only Flag [$scheduled_only_once]" \
  589.         M    "Back to main menu" 2>$TMP/$DIALOGFILE
  590.     if [ $? = 0 ]
  591.     then
  592.         case `cat $TMP/$DIALOGFILE` in
  593.             T)    enter_time
  594.                 Configuration_changed=YES
  595.                 ;;
  596.             B)    schedule
  597.                 echo "$0 --scheduled-backup $schedulename" | at $scheduletime 
  598.                 exit
  599.                 ;;
  600.             R)    Restore_part_I
  601.                 if [ "$restore_part_I" = "FAILED" ]
  602.                 then
  603.                     return
  604.                 fi
  605.                 schedule
  606.                 pwd
  607.                 read
  608.                 echo "$0 --scheduled-restore $schedulename" | at $scheduletime 
  609.                 exit
  610.                 ;;
  611.             M)    schedule=NO
  612.                 return
  613.                 ;;
  614.             O)    $DIALOG --title "Schedule Once Only Flag" --yesno "
  615. If you have specified a time setting that
  616. calls this backup more than only once, its
  617. configuration file must not be removed, so
  618. please choose <NO> here.
  619.  
  620. If you want this backup to be performed
  621. only once, it can savely remove its confi-
  622. guration file on termination, so please
  623. choose <YES>.
  624.  
  625. Perform backup only once?
  626. "  16  47
  627.                 if [ $? = 0 ]
  628.                 then
  629.                     scheduled_only_once=YES
  630.                 else
  631.                     scheduled_only_once=NO
  632.                 fi
  633.                 Configuration_changed=YES
  634.                 ;;
  635.         esac
  636.     else
  637.         schedule=NO
  638.         return
  639.     fi
  640.     done
  641. }
  642.  
  643. Verify()    # accepts option "auto" to avoid prompt for medium
  644. {
  645.     if [ "$Verify_src_loaded" != "YES" ]
  646.     then
  647.         . "$SRCDIR/$VERIFY_SRC"
  648.     fi
  649.     Verify_II $1
  650. }
  651.  
  652. cleanup()
  653. {
  654.     rm -rf $TMPFILES
  655.     rmdir $TMP 2>/dev/null
  656. }
  657.  
  658. set_multivolume()
  659. {
  660.     multivolume=YES
  661.  
  662.     if [ "$archive_format" = "TAR" ]
  663.     then
  664.         if [ "$protect_newer" = "YES" ]
  665.         then
  666.             protect_newer=NO
  667.             Configuration_changed=YES
  668.             MsgBox \
  669. "You have selected TAR archive format
  670. and chosen to protect newer files during
  671. restore. This is not possible with tar.
  672.  
  673. Disabling protection feature."
  674.         fi
  675.  
  676.         if [ "$compression" != "NONE" ]
  677.         then
  678.             compression=NONE
  679.             Configuration_changed=YES
  680.             MsgBox "Switching off compression for multi-\nvolume tar-archives."
  681.         fi
  682.         if [ "$double_buffering" = "YES" ]
  683.         then
  684.             double_buffering=NO
  685.             Configuration_changed=YES
  686.             MsgBox "Switching off double buffering\nfor multivolume tar-archives."
  687.         fi
  688.     fi
  689. }
  690.  
  691. #
  692. #    check wether combination of options is valid:
  693. #
  694. Check_Settings()
  695. {
  696.     if [ "$archive_format" = "TAR" ]
  697.     then
  698.         if [ "$multivolume" = "YES" ]
  699.         then
  700.             if [ "$compression" != "NONE" ]
  701.             then
  702.                 ErrorBox \
  703. "If you want to use compressed multivolume archives,
  704. you must use the AFIO-format, TAR is not capable of
  705. this. Otherwise, you cannot compress or just write
  706. archives of at most one volume's length.
  707. Setting archive format to AFIO."
  708.                 archive_format=AFIO
  709.                 Configuration_changed=YES
  710.             fi
  711.             if [ "$double_buffering" = "YES" ]
  712.             then
  713.                 ErrorBox \
  714. "You cannot use double buffering with multivolume
  715. archives in TAR-format. 
  716. As TAR does not support compression with multi-
  717. volume archives, this should not be necessary
  718. anyway.
  719. Switching off double buffering."
  720.                 double_buffering=NO
  721.                 Configuration_changed=YES
  722.             fi
  723.         fi
  724.     fi
  725.  
  726.  
  727.     if [ "$double_buffering" = "YES" ]
  728.     then
  729.         if [ -z "$ddbufsize" ]
  730.         then
  731.             ErrorBox \
  732. "You must specify a buffersize when using double
  733. buffering.
  734. Setting it to 4096k."
  735.             ddbufsize=4096k
  736.             Configuration_changed=YES
  737.         fi
  738.         if [ "$device_type" = "FLOPPY" ]
  739.         then
  740.             ErrorBox \
  741. "You selected double buffering for a floppy
  742. drive. This is not possible.
  743. Disabling double buffering."
  744.         double_buffering=NO
  745.         Configuration_changed=YES
  746.         fi
  747.     fi
  748.     if [ "$use_patterns" = "YES" -a "$directoriesonly" = "YES" ]
  749.     then
  750.         ErrorBox \
  751. "You are trying to use include/exclude shell
  752. patterns together with the \"Directories-Only\"
  753. setting. This is not possible, sorry.
  754.  
  755. Disabling \"Directories-Only\" setting."
  756.         directoriesonly=NO
  757.         Configuration_changed=YES
  758.     fi
  759.     if [ "$archive_format" = "AFIO"  -a "$directoriesonly" = "YES" ]
  760.     then
  761.         ErrorBox \
  762. "AFIO format archives cannot use the
  763. Directories-Only-Flag. 
  764.  
  765. It is switched off now."
  766.         directoriesonly=NO
  767.         Configuration_changed=YES
  768.     fi
  769.     if [ "$verify_archive" = "YES" -a "$device_type" = "BLOCKDEV" ]
  770.     then
  771.         ErrorBox \
  772. "Verify for BLOCKDEV archives is
  773. not implemented currently.
  774.  
  775. Switching off Verify-Setting."
  776.         Configuration_changed=YES
  777.     fi
  778.     if [ "$archive_format" = "AFIO" -a "$compression" = "PGP" -a "$HasAFIO242" != "YES" ]
  779.     then
  780.         MsgBox \
  781. "You are using pgp-encryption with
  782. an \"old\" afio program. This is 
  783. not safe! See the manual or upgrade
  784. to an afio version newer than 2.4.2!
  785. "
  786.     fi
  787. }    
  788.  
  789. ############################### MENU ROUTINES ##################
  790.  
  791. Compression_Menu()
  792. {
  793.     while :
  794.     do
  795.         $DIALOG   --title " Compression menu " --menu "\n\
  796. Please choose one of the following compression methods. Before using\n\
  797. pgp(1) for public key encryption, you should know what you are doing!\n\n\
  798. The current compression is $compression, Options: $compress_options\n" 19 75 7 \
  799.         N    "No compression" \
  800.         G    "Compress using Gzip" \
  801.         C    "Compress using Compress" \
  802.         P    "Compress + Encrypt using Pgp" \
  803.         O    "Set Command-line Options for compression program" \
  804.         D    "Set Command-line Options for decompressing" \
  805.         "<"    "Return to Backup Parameters Menu" 2>$TMP/$DIALOGFILE
  806.     if [ $? = 0 ]
  807.     then
  808.         case `cat $TMP/$DIALOGFILE` in
  809.         N)    compression=NONE
  810.             Configuration_changed=YES
  811.             ;;
  812.         G)    compression=GZIP
  813.             Configuration_changed=YES
  814.             ;;
  815.         C)    compression=COMPRESS
  816.             Configuration_changed=YES
  817.             ;;
  818.         P)    compression=PGP
  819.             $DIALOG   --inputbox "Please enter name of pgp key:" 8 75 2>$TMP/$DIALOGFILE 
  820.             if [ $? = 0 ] && test -n "`cat $TMP/$DIALOGFILE`"
  821.             then
  822.                 pgpkey=`cat $TMP/$DIALOGFILE`
  823.                 Configuration_changed=YES
  824.             fi
  825.             ;;
  826.         O)    $DIALOG   --inputbox "Please enter any optional command line arguments\n\
  827. for the compression program (e.g. -1 for gzip).\n\
  828. Default is: \"$compress_options\"\n(Enter a single space for no options.)" 13 75 2>$TMP/$DIALOGFILE
  829.             if [ $? = 0 ]
  830.             then
  831.                 if [ "`cat $TMP/$DIALOGFILE`" != "" ] ; then
  832.                     compress_options=`cat $TMP/$DIALOGFILE`
  833.                     Configuration_changed=YES
  834.                 fi
  835.             fi
  836.             ;;
  837.         D)    $DIALOG   --inputbox "Please enter any optional command line arguments\n\
  838. for the compression program when used for decompressing.\n\
  839. Default is: \"$decompress_options\"\n(Enter a single space for no options.)" 13 75 2>$TMP/$DIALOGFILE
  840.             if [ $? = 0 ]
  841.             then
  842.                 if [ "`cat $TMP/$DIALOGFILE`" != "" ] ; then
  843.                     decompress_options=`cat $TMP/$DIALOGFILE`
  844.                     Configuration_changed=YES
  845.                 fi
  846.             fi
  847.             ;;
  848.  
  849.         "<")    return
  850.             ;;
  851.         esac
  852.     else
  853.         return
  854.     fi
  855.     done
  856. }
  857.  
  858. Floppy_Format_Menu()
  859. {
  860.     while : ; do
  861.         $DIALOG --title " Floppy Format Menu " --menu "\n\
  862. Please choose a disk format to use:\n(current: $floppy_format)\n" 18 70 7\
  863.         "1722/1440"    "1.7Mb  on a 3.5  drive" \
  864.         "1440/1440"    "1.44Mb on a 3.5 or 5.25 drive" \
  865.         "720/1440"    "720Kb  on a 3.5  drive" \
  866.         "1200/1200"    "1.2Mb  on a 5.25 drive" \
  867.         "720/1200"    "720Kb  on a 5.25  drive" \
  868.         "User defined"  "Enter your own value from /etc/fdprm" \
  869.         "<"        "Return to Device Menu" 2>$TMP/$DIALOGFILE 
  870.     if [ $? = 0 ]
  871.     then
  872.         case `cat $TMP/$DIALOGFILE` in
  873.             "<")    return
  874.                 ;;
  875.             "User definded")
  876.                 $DIALOG --inputbox \
  877. "Please enter your own value for a floppy format description,
  878. like specified in \"/etc/fdprm\":
  879. " 7 75 2>$TMP/$DIALOGFILE
  880.                 if [ $? = 0 ]
  881.                 then
  882.                     tmp=`cat $TMP/$DIALOGFILE`
  883.                     if [ "$tmp" != "" ]
  884.                     then
  885.                         floppy_format="$tmp"
  886.                         Configuration_changed=YES
  887.                     fi
  888.                 fi
  889.                 ;;
  890.             *)    floppy_format=`cat $TMP/$DIALOGFILE`
  891.                 Configuration_changed=YES
  892.                 ;;
  893.         esac
  894.     else
  895.         return
  896.     fi
  897.     done
  898. }
  899.  
  900. test_tape_device()
  901. {
  902.     if [ "Autodetect_src_loaded" != "YES" ]
  903.     then
  904.         . $SRCDIR/$AUTODETECT_SRC
  905.     fi
  906.  
  907.     insert_media && \
  908.     $DIALOG --title " Warning! " --yesno \
  909. "
  910. This test will erase any data on the tape!
  911. Are you sure that you want to continue?" 8 50
  912.     if [ $? = 0 ]
  913.     then
  914.         test_tape_device_II "$device"
  915.         if [ $? = 0 ]
  916.         then
  917.             MsgBox "Your tape drive 
  918. \"$device\" 
  919. is compatible with KBackup."
  920.         else
  921.             MsgBox "Your tape drive
  922. \"$device\"
  923. is a rewind-on-close device and 
  924. therefore not compatible with 
  925. KBackup. Please choose a non-re-
  926. winding one and try again."    
  927.         fi
  928.     fi
  929. }
  930.  
  931. autodetect_tape_device()
  932. {
  933.     if [ "Autodetect_src_loaded" != "YES" ]
  934.     then
  935.         . $SRCDIR/$AUTODETECT_SRC
  936.     fi
  937.     autodetect_tape_device_II 
  938.     autodetect_tape_menu
  939. }
  940.  
  941. Device_Menu()
  942. {
  943.     while : ; do
  944.         $DIALOG --title " Device Menu " --menu "\n\
  945. Choose a device for your backup and optionally set the device related\n\
  946. options. If you are choosing a tape drive, it must not do an automatic 
  947. rewind at the end of a file being written.
  948. Autodetection might not work on your system, use it with care!
  949.  
  950. Current setting: $device" 24 76 11 \
  951.         A        "Attempt to autodetect tape device"\
  952.         C        "Check tape drive for compatibility"\
  953.         D        "Set device type                   [$device_type]"\
  954.         "Specify"     "Enter your own device/archive file"\
  955.         "/dev/fd0"     "First floppy drive"\
  956.         "/dev/fd1"     "Second floppy drive"\
  957.         T        " Blockdev filesystem type         [$blockdev_fs_type]"\
  958.         M        " Blockdev make filesystem command [$blockdev_mkfs]"\
  959.         F        "Set Floppy format                 [$floppy_format]"\
  960.         R        "Set device for resetting driver   [$resetdevice]"\
  961.         "<"        "Return to KBackup Config Menu" 2>$TMP/$DIALOGFILE
  962.     if [ $? = 0 ]
  963.     then
  964.         case `cat $TMP/$DIALOGFILE` in
  965.         A)    autodetect_tape_device
  966.             ;;
  967.         F)    Floppy_Format_Menu
  968.             ;;
  969.         D)    case "$device_type" in
  970.                 TAPE)
  971.                     device_type=FLOPPY
  972.                     ;;
  973.                 FLOPPY)
  974.                     device_type=BLOCKDEV
  975.                     ;;
  976.                 BLOCKDEV)
  977.                     device_type=TAPE
  978.                     ;;
  979.             esac
  980.             Configuration_changed=YES
  981.             ;;
  982.         /dev/fd0|/dev/fd1)
  983.             device_type=FLOPPY
  984.             device=`cat $TMP/$DIALOGFILE`
  985.             Configuration_changed=YES
  986.             Floppy_Format_Menu
  987.             ;;
  988.         Specify)    $DIALOG   --inputbox "Please specify the device/file to use.\n(default: $device)" \
  989.             9 75 2>$TMP/$DIALOGFILE
  990.             if [ $? = 0 ]
  991.             then
  992.                 newdevice=`cat $TMP/$DIALOGFILE`
  993.                 if [ -n "$newdevice" ]
  994.                 then
  995.                     device="$newdevice"
  996.                     Configuration_changed=YES
  997.                 fi
  998.                 if [ -c "$device" ] ; then
  999.                     device_type=TAPE
  1000.                     MsgBox "You specified a character device,\nassuming it is a tape streamer."
  1001.                 else
  1002.                     if [ -L "$device" ] ; then
  1003.                         device_type=TAPE
  1004.                         MsgBox "You specified a symbolic link,\nassuming it is a tape streamer."
  1005.                     else
  1006.                         if [ -b "$device" ] ; then
  1007.                             device_type=FLOPPY
  1008.                             MsgBox "You specified a block device,\nassuming it is a floppy drive."
  1009.                         fi
  1010.                     fi
  1011.                 fi
  1012.             fi
  1013.             ;;
  1014.         R)    $DIALOG   --inputbox "Please specify the device for resetting the driver:\n(default: $resetdevice)\nThis seems to work only with the QIC02-driver!\n" \
  1015.             11 75 2>$TMP/$DIALOGFILE
  1016.             if [ $? = 0 ] && test -n "`cat $TMP/$DIALOGFILE`"
  1017.             then
  1018.                 if [ -c `cat $TMP/$DIALOGFILE` ] ; then
  1019.                     resetdevice=`cat $TMP/$DIALOGFILE`
  1020.                     Configuration_changed=YES
  1021.                 else
  1022.                     $DIALOG   --msgbox "\nNo character device!\nKeeping old value." 5 40
  1023.                 fi
  1024.             fi
  1025.             ;;
  1026.         "<")    return
  1027.             ;;
  1028.         T)    $DIALOG --title " Filesystem type for mountable block devices " \
  1029.                 --inputbox \
  1030. "Please specify the filesystem type to use on the block
  1031. device. KBackup will automatically format and error check
  1032. every backup medium.
  1033.  
  1034. Recommended: \"minix\" on floppies, \"ext2\" for removable
  1035. hard drives.
  1036. "  14 75 2>$TMP/$DIALOGFILE
  1037.             if [ $? = 0 ]
  1038.             then
  1039.                 tmp=`cat $TMP/$DIALOGFILE`
  1040.                 if [ "$tmp" != "" ]
  1041.                 then
  1042.                     blockdev_fs_type="$tmp"
  1043.                     Configuration_changed=YES
  1044.                 fi
  1045.             fi
  1046.             ;;                
  1047.         M)    $DIALOG --title " Formatting command for mountable block devices " \
  1048.             --inputbox \
  1049. "Please specify the command to execute for formatting a block device. 
  1050. KBackup will automatically create a filesystem on every medium and 
  1051. afterwards mount it, using the current filesystem setting. Of course, 
  1052. the formatting command must match the setting for the filesystem type.
  1053.  
  1054. Current filesystem type setting: \"$blockdev_fs_type\"
  1055.  
  1056. The string \$device will be changed into the actual device name.
  1057.  
  1058. Suggested values:
  1059.     mkfs -t minix \$device nblocks   : to create a minix fs
  1060.     mkfs -t ext2 \$device         : to create an ext2 fs
  1061.     fdformat \$device && mkfs -t minix \$device 
  1062.          : to low-level format a floppy and put a minix fs on it
  1063.          
  1064. (Just press ENTER to keep the current value.)" 23 75 2>$TMP/$DIALOGFILE
  1065.         if [ $? = 0 ]
  1066.         then
  1067.             tmp=`cat $TMP/$DIALOGFILE`
  1068.             if [ "$tmp" != "" ]
  1069.             then
  1070.                 blockdev_mkfs="$tmp"
  1071.                 Configuration_changed=YES
  1072.             fi
  1073.         fi
  1074.         ;;
  1075.         C)    # check tape drive for compatibility
  1076.             test_tape_device
  1077.         ;;
  1078.         esac
  1079.     else
  1080.         return
  1081.     fi
  1082.     done
  1083. }
  1084.  
  1085. Multivolume_Menu()
  1086. {
  1087.     while : ; do
  1088.         $DIALOG --title " Multivolume Archives Menu " --menu "
  1089. Options relevant for handling archives that span more than one
  1090. physical volume.
  1091. The MultiBuf program is able to automatically detect the end of a 
  1092. backup medium and will prompt you to change it. It also adds se-
  1093. quence information to the archive, preventing you from using the 
  1094. backup media in the wrong order when restoring.
  1095.  
  1096. Normally, you do not need to change these settings." 23 72 7\
  1097.             S    "Set MultiBuf blocksize                 [$multibuf_blksize]"\
  1098.             N    "Set number of MultiBuf blocks per call [$multibuf_nblocks]"\
  1099.             I    "Use sequence information in MultiBuf   [$multibuf_seq_info]"\
  1100.             E    "Set command to execute at end of tape"\
  1101.             B    "Set command to execute at begin of new tape"\
  1102.             T    "Toggle use of MultiBuf                 [$use_multibuf]"\
  1103.             "<"    "Return to Parameters Menu" 2>$TMP/$DIALOGFILE
  1104.         if [ $? = 0 ]
  1105.         then
  1106.         case `cat $TMP/$DIALOGFILE` in
  1107.             I)    if [ $multibuf_seq_info = YES ]
  1108.                 then
  1109.                     multibuf_seq_info=NO
  1110.                 else
  1111.                     multibuf_seq_info=YES
  1112.                 fi
  1113.                 Configuration_changed=YES
  1114.                 ;;
  1115.             T)    if [ "$use_multibuf" = "YES" ]
  1116.                 then
  1117.                     use_multibuf=NO
  1118.                 else
  1119.                     use_multibuf=YES
  1120.                 fi
  1121.                 Configuration_changed=YES
  1122.                 ;;
  1123.             S)    $DIALOG   --inputbox \
  1124. "Please give the size of a single block in bytes.
  1125. This should be a small kilobyte value, like e.g. 4096.
  1126. (default: $multibuf_blksize)\n" \
  1127.                 11 75 2>$TMP/$DIALOGFILE
  1128.                 if [ $? = 0 ]
  1129.                 then
  1130.                     multibuf_blksize=`cat $TMP/$DIALOGFILE`
  1131.                     Configuration_changed=YES
  1132.                 fi
  1133.                 ;;
  1134.             N)    $DIALOG   --inputbox \
  1135. "Please give the number of blocks for buffering. Multiplied with the
  1136. blocksize this should give a reasonable big buffer. The bigger it is
  1137. the less overhead it causes. The smaller it is, the more effective 
  1138. will MultiBuf use your volumes. For tapes I would recommend something
  1139. a total buffer size of 100K (blocksize=1024, number of blocks=100).
  1140. In general, the total buffer size must(!) be smaller than the size
  1141. of your volume.
  1142. (default: $multibuf_nblocks)\n"\
  1143.                 16 75 2>$TMP/$DIALOGFILE 
  1144.                 if [ $? = 0 ]
  1145.                 then
  1146.                     multibuf_nblocks=`cat $TMP/$DIALOGFILE`
  1147.                     Configuration_changed=YES
  1148.                 fi
  1149.                 ;;
  1150.             "<")    return
  1151.                 ;;
  1152.             E)    $DIALOG --inputbox \
  1153. "The command specified here is used by MultiBuf to either prompt
  1154. the user to change tapes or to tell an automatic loading mechanism
  1155. to change tapes. However, this command will be executed whenever
  1156. MultiBuf detects an end of tape.
  1157.  
  1158. If you want to use the default value, enter DEFAULT .
  1159. If you want to keep the current value, just press enter.
  1160.  
  1161. The current value is:
  1162. \"$multibuf_cmd1\"\n" 17 74 2>$TMP/$DIALOGFILE
  1163.                 if [ $? = 0 ]
  1164.                 then
  1165.                     tmp=`$SED "1,$ s/"/\\"/g" <$TMP/$DIALOGFILE`
  1166.                     if [ "$tmp" != "" ]
  1167.                     then
  1168.                         multibuf_cmd1="$tmp"
  1169.                         Configuration_changed=YES
  1170.                     fi
  1171.                 fi
  1172.                 ;;
  1173.             B)    $DIALOG --inputbox \
  1174. "The command specified here is called by MultiBuf after the
  1175. tape has been changed. Usually, after changing tapes, you
  1176. should execute something like a \"mt rewind\".
  1177. Even if your tape is auto-rewinding any new cartridge, you
  1178. should issue the rewind command. (QIC-02 causes problems
  1179. otherwise.)
  1180.  
  1181. To use this default value, enter DEFAULT .
  1182. If you want to keep the current value, just press enter.
  1183.  
  1184. The current value is:
  1185. \"$multibuf_cmd2\"\n" 20 74 2>$TMP/$DIALOGFILE
  1186.                 if [ $? = 0 ]
  1187.                 then
  1188.                     tmp=`$SED "1,$ s/"/\\"/g" <$TMP/$DIALOGFILE`
  1189.                     if [ "$tmp" != "" ]
  1190.                     then
  1191.                         multibuf_cmd2="$tmp"
  1192.                         Configuration_changed=YES
  1193.                     fi
  1194.                 fi
  1195.                 ;;
  1196.  
  1197.         esac
  1198.         else
  1199.             return
  1200.         fi
  1201.     done
  1202. }
  1203.  
  1204.                 
  1205.  
  1206. Advanced_Options_Menu()
  1207. {
  1208.  
  1209.     while : ; do
  1210.         $DIALOG   --title " Advanced Options Menu " --menu "\n\
  1211. The options in this menu deeply affect the operation of KBackup. You\n\
  1212. should know what you are doing before making any changes. If you are\n\
  1213. not sure, go back to the main menu and read the manual first.\n" 20 77 8 \
  1214.             S    "Backup only files specified               [$specifiedfilesonly]"\
  1215.             N    "    Edit list of files to include in backup" \
  1216.             I    "    Initialise list of files to include" \
  1217.             X    "Set Find-Expert Mode                      [$findxpertmode]"\
  1218.             O    "Set find-options for Find-Expert Mode"\
  1219.             E    "Set option to manually edit list of files [$manualedit]"\
  1220.             D    "Toggle Directories-Only Flag              [$directoriesonly]" \
  1221.             "<"    "Return to File Selection Menu" 2>$TMP/$DIALOGFILE
  1222.         if [ $? = 0 ]
  1223.         then
  1224.         case    `cat $TMP/$DIALOGFILE` in
  1225.             D)    if [ "$directoriesonly" = "YES" ] ; then
  1226.                     directoriesonly=NO
  1227.                 else
  1228.                     directoriesonly=YES
  1229.                 fi
  1230.                 Configuration_changed=YES
  1231.                 ;;
  1232.             S)    if [ "$specifiedfilesonly" = "YES" ] ; then
  1233.                     specifiedfilesonly=NO
  1234.                 else
  1235.                     specifiedfilesonly=YES
  1236.                 fi
  1237.                 Configuration_changed=YES
  1238.                 ;;
  1239.             N)    $EDITOR "$datadir/$configname/Include_Files"
  1240.                 ;;
  1241.             I)    InfoBox "Reading files..." 
  1242.                 create_dir_list
  1243.                 cp -f "$TMP/$DIRLISTFILE" "$datadir/$configname/Include_Files"
  1244.                 ;;
  1245.             E)    if [ "$manualedit" = "YES" ] ; then
  1246.                     manualedit=NO
  1247.                 else
  1248.                     manualedit=YES
  1249.                 fi
  1250.                 Configuration_changed=YES
  1251.                 ;;
  1252.             X)    if [ "$findxpertmode" = "YES" ] ; then
  1253.                     findxpertmode=NO
  1254.                 else
  1255.                     findxpertmode=YES
  1256.                 fi
  1257.                 Configuration_changed=YES
  1258.                 ;;
  1259.             O)    $DIALOG   --inputbox "Please enter options for find(1) command:\n(default: $findxpertflags)"\
  1260.                     11 75 2>$TMP/$DIALOGFILE
  1261.                 if [ $? = 0 ]
  1262.                 then
  1263.                     if [ -n "`cat $TMP/$DIALOGFILE`" ]
  1264.                     then
  1265.                         findxpertflags="`cat $TMP/$DIALOGFILE`"
  1266.                         Configuration_changed=YES
  1267.                     fi
  1268.                 fi
  1269.                 ;;
  1270.             "<")    return
  1271.             ;;
  1272.         esac
  1273.         else
  1274.             return
  1275.         fi
  1276.     done
  1277. }
  1278.  
  1279.  
  1280. File_Selection_Menu()
  1281. {
  1282.     while : ; do
  1283.         $DIALOG   --title " File Selection Menu " --menu "\n\
  1284. This menu allows you to change the selection criteria for files to
  1285. be backed up.\n" 22 77 10 \
  1286.             E    "Toggle Local Filesystem Mode           [$local]" \
  1287.             I    "Toggle Incremental Mode                [$incremental]" \
  1288.             D    "Set date for incremental backup"\
  1289.             F    "Edit list of files to exclude" \
  1290.             X    "Set shell pattern for files to exclude" \
  1291.             N    "Set shell pattern for files to include" \
  1292.             T    "Toggle use of include/exclude patterns [$use_patterns]" \
  1293.             P    "Protect newer files during restore [$protect_newer]" \
  1294.             A    "Set advanced options" \
  1295.             "<"    "Return to Configuration Menu" 2>$TMP/$DIALOGFILE
  1296.         if [ $? = 0 ]
  1297.         then
  1298.         case    `cat $TMP/$DIALOGFILE` in
  1299.             E)    if [ "$local" = "YES" ] ; then
  1300.                     local=NO
  1301.                 else
  1302.                     local=YES
  1303.                 fi
  1304.                 Configuration_changed=YES
  1305.                 ;;
  1306.             "P")    if [ "$protect_newer" = "YES" ]
  1307.                 then
  1308.                     protect_newer=NO
  1309.                 else
  1310.                     protect_newer=YES
  1311.                 fi
  1312.                 Configuration_changed=YES
  1313.                 ;;
  1314.             I)    if [ "$incremental" = "YES" ] ; then
  1315.                     incremental=NO
  1316.                 else
  1317.                     incremental=YES
  1318.                 fi
  1319.                 Configuration_changed=YES
  1320.                 ;;
  1321.             D)    $DIALOG   --inputbox \
  1322.                 "Please specify the date in MM/DD/YY HH:MM format:\n(default: \"$datestamp\"):" 9 75 2>$TMP/$DIALOGFILE
  1323.                 if [ $? = 0 ]
  1324.                 then
  1325.                     if [ "`cat $TMP/$DIALOGFILE`" != "" ]
  1326.                     then
  1327.                         datestamp=`cat $TMP/$DIALOGFILE`
  1328.                         Configuration_changed=YES
  1329.                     fi
  1330.                 fi
  1331.                 ;;
  1332.             F)    $EDITOR "$datadir/$configname/Exclude_Files"
  1333.                 $SED "1,$ s/^\///g" <"$datadir/$configname/Exclude_Files" >$TMP/$TMPFILE 
  1334.                 cat <$TMP/$TMPFILE >"$datadir/$configname/Exclude_Files" 
  1335.                 ;;
  1336.             X)    $EDITOR "$datadir/$configname/Exclude_Patterns"
  1337.                 ;;
  1338.             N)    $EDITOR "$datadir/$configname/Include_Patterns"
  1339.                 ;;
  1340.             T)    if [ "$use_patterns" = "NO" ]
  1341.                 then
  1342.                     use_patterns=YES
  1343.                 else
  1344.                     use_patterns=NO
  1345.                 fi
  1346.                 Configuration_changed=YES
  1347.                 ;;
  1348.             A)    Advanced_Options_Menu
  1349.                 ;;
  1350.             "<")    return
  1351.             ;;
  1352.         esac
  1353.         else
  1354.             return
  1355.         fi
  1356.     done
  1357. }
  1358.  
  1359.  
  1360. Remote_mode_Menu()
  1361. {
  1362.     while : ; do
  1363.         $DIALOG --title " Remote Mode Menu " --menu "
  1364. Here you can set the options for accesing a remote
  1365. backup device, e.g. a tape drive on another computer
  1366. somewhere in the network.
  1367.  
  1368. This is still ALPHA and might not work for you!
  1369.  
  1370. " 23 77 5 \
  1371.         T    "Toggle use of remote mode    [$remote_mode]"\
  1372.         H    "Set hostname to connect to   [$remote_host]"\
  1373.         U    "Set user to use for login    [$remote_uid]"\
  1374.         V    "Verify whether settings work"\
  1375.         "<"    "Return to Config Menu" 2>$TMP/$DIALOGFILE
  1376.         if [ $? = 0 ]
  1377.         then
  1378.         case `cat $TMP/$DIALOGFILE` in
  1379.         T)    if [ "$remote_mode" = "YES" ] ; then
  1380.                 remote_mode=NO ; else
  1381.                 remote_mode=YES;
  1382.             fi
  1383.             Configuration_changed=YES
  1384.             ;;
  1385.         H)    $DIALOG --inputbox "Please specify the host to connect to:" \
  1386.             9 75 2>$TMP/$DIALOGFILE 
  1387.             if [ $? = 0 ] && test -n "`cat $TMP/$DIALOGFILE`"
  1388.                 then
  1389.                     remote_host=`cat $TMP/$DIALOGFILE`
  1390.                     Configuration_changed=YES
  1391.                 fi
  1392.             ;;
  1393.         U)    $DIALOG --inputbox "\
  1394. Please specify the username to use for connecting to the remote host. 
  1395. The user must have write access to the backup device. The user must
  1396. also be existent on this machine as well as the remote one and allow
  1397. remote login using rsh(1) without password prompting.
  1398.  
  1399. (A setting that works fine for me, is to use adm as the username and
  1400. put the computer KBackup is running on into the /ets/hosts.equiv file
  1401. of the remote computer, to allow rsh(1) to work.)
  1402.  
  1403. NOTE: The MultiBuf program must be available on the remote computer!
  1404.  
  1405. " 23 75 2>$TMP/$DIALOGFILE 
  1406.             if [ $? = 0 ] && test -n "`cat $TMP/$DIALOGFILE`"
  1407.             then
  1408.                 remote_uid=`cat $TMP/$DIALOGFILE`
  1409.                 Configuration_changed=YES
  1410.             fi
  1411.             ;;
  1412.         V)    InfoBox "Changing my user ID..."
  1413.             su "$remote_uid" -c echo 2>$STDERR 1>/dev/null
  1414.             check_error
  1415.             if [ $? != 0 ] ; then break ; fi
  1416.             
  1417.             InfoBox "Trying to connect..."
  1418.             su "$remote_uid" -c "rsh $remote_host echo" 2>$STDERR 1>/dev/null
  1419.             check_error
  1420.             if [ $? != 0 ] ; then break ; fi
  1421.             
  1422.             InfoBox "Checking device..."
  1423.             su "$remote_uid" -c "rsh $remote_host \"test -w $device\" " 2>$STDERR 
  1424.             check_error
  1425.             if [ $? != 0 ] ; then
  1426.                 MsgBox "Unable to open device for writing."
  1427.             fi
  1428.             ;;
  1429.         "<")    return
  1430.             ;;
  1431.         esac
  1432.         fi
  1433.     done
  1434. }
  1435.  
  1436. Archive_Type_Menu()
  1437. {
  1438.     while : ; do
  1439.         $DIALOG --title " Archive Type Menu " --menu \
  1440. "KBackup can use either tar(1) or afio(1) to handle its archives.
  1441. Using these well tested programs ensures compatibility across
  1442. platforms and high reliability.
  1443. Tar is the more tested and portable one, while afio offers much
  1444. improved functionality, especially when used with encryption or
  1445. compression. Using comrpression with tar is unsafe.
  1446.  
  1447. Currently set archive handler: $archive_format
  1448. " 21 77 5 \
  1449.             A    "Use Afio"\
  1450.             T    "Use Tar" \
  1451.             F    "Set additional command line parameters for Afio" \
  1452.             R    "Set additional command line parameters for Tar" \
  1453.             "<"    "Return to Configure KBackup Menu" 2>$TMP/$DIALOGFILE
  1454.         if [ $? = 0 ]
  1455.         then
  1456.         case    `cat $TMP/$DIALOGFILE` in
  1457.             A)    archive_format=AFIO
  1458.                 Configuration_changed=YES
  1459.                 ;;
  1460.             T)    archive_format=TAR
  1461.                 Configuration_changed=YES
  1462.                 ;;
  1463.             F)    $DIALOG   --inputbox \
  1464. "Additional command line parameters to pass to Afio:
  1465. (Current setting: \"$afio_user_opts\")
  1466. Enter a single space for no options, press ENTER to keep
  1467. existing ones." \
  1468.                 12 75 2>$TMP/$DIALOGFILE
  1469.                 if [ $? = 0 ] && test -n "`cat $TMP/$DIALOGFILE`"
  1470.                 then
  1471.                     afio_user_opts=`cat $TMP/$DIALOGFILE`
  1472.                     Configuration_changed=YES
  1473.                 fi
  1474.                 ;;
  1475.             R)    $DIALOG   --inputbox \
  1476. "Additional command line parameters to pass to Tar:
  1477. (Current setting: \"$afio_user_opts\")
  1478. Enter a single space for no options, press ENTER to keep
  1479. existing ones." \
  1480.                 12 75 2>$TMP/$DIALOGFILE
  1481.                 if [ $? = 0 ] && test -n "`cat $TMP/$DIALOGFILE`"
  1482.                 then
  1483.                     tar_user_opts=`cat $TMP/$DIALOGFILE`
  1484.                     Configuration_changed=YES
  1485.                 fi
  1486.                 ;;
  1487.             "<")    return
  1488.                 ;;
  1489.         esac
  1490.         else
  1491.             return
  1492.         fi
  1493.     done
  1494. }
  1495.  
  1496. Config_KBackup_Menu()
  1497. {
  1498.     while : ; do
  1499.         $DIALOG --title " Config KBackup Menu " --menu "" 24 77 17 \
  1500.             C    "Create Report on Backup                 [$CreateReport]"\
  1501.             E    "Set name of editor to use               [$EDITOR]" \
  1502.             F    "Follow backup/restore-process on screen [$followtarops]"\
  1503.             L    "Toggle creation of restore-log file     [$restore_write_log]"\
  1504.             P    "Set compression/encryption mode         [$compression, Opt:\"$compress_options\"]"\
  1505.             B    "Toggle use of double buffering          [$double_buffering]"\
  1506.             S    "Set memory size for double buffering    [$ddbufsize]"\
  1507.             V    "Verify archive after writing            [$verify_archive]"\
  1508.             Y    "Archive Type Menu                       [$archive_format]"\
  1509.             T    "Change KBackup directory                [$datadir]"\
  1510.             U    "Multivolume Archives handling"\
  1511.             D    "Select device for backup                [$device]"\
  1512.             W    "Toggle Auto-Rewind                      [$AutoRewind]"\
  1513.             R    "Remote mode settings"\
  1514.             M    "Set directory for temporary files       [$TMP]"\
  1515.             O    "Set command for viewing online manual"\
  1516.             "<"    "Return to Configuration Menu" 2>$TMP/$DIALOGFILE
  1517.         if [ $? = 0 ]
  1518.         then
  1519.         case    `cat $TMP/$DIALOGFILE` in
  1520.             C)    $DIALOG   --title  " Report Creation" --inputbox "
  1521. KBackup can create a report of the backup creation
  1522. and optionally mail it to someone or print it.
  1523.  
  1524. Here you can give the command to pass the report to, e.g.:
  1525.  
  1526.   \"lpr\"              -- this will simply print the report
  1527.   \"mail sysadmin\"    -- this will mail it to \"sysadmin\"
  1528.   \"cat >/tmp/report\" -- this will save it in \"/tmp/report\"
  1529.  
  1530. Just press ENTER if you want to discard the report.
  1531. " 20 65 2>$TMP/$DIALOGFILE
  1532.             if [ $? = 0 ]
  1533.             then
  1534.                 tmp=`cat $TMP/$DIALOGFILE`
  1535.                 if [ "$tmp" != "" ]
  1536.                 then
  1537.                     Configuration_changed=YES
  1538.                     ReportCommand="$tmp"
  1539.                     CreateReport=YES
  1540.                 else
  1541.                     CreateReport=NO
  1542.                 fi
  1543.             else
  1544.                 CreateReport=NO
  1545.             fi
  1546.             ;;
  1547.             E)    $DIALOG   --inputbox "Please specify the editor you want to use:" \
  1548.                     9 75 2>$TMP/$DIALOGFILE
  1549.                 if [ $? = 0 ] && test -n "`cat $TMP/$DIALOGFILE`"
  1550.                 then
  1551.                     EDITOR=`cat $TMP/$DIALOGFILE`
  1552.                     Configuration_changed=YES
  1553.                 fi
  1554.                 ;;
  1555.             R)    Remote_mode_Menu
  1556.                 ;;
  1557.             F)    if [ "$followtarops" = "YES" ] ; then
  1558.                     followtarops=NO
  1559.                 else
  1560.                     followtarops=YES
  1561.                 fi
  1562.                 Configuration_changed=YES
  1563.                 ;;
  1564.             L)    if [ "$restore_write_log" = "YES" ] ; then
  1565.                     restore_write_log=NO
  1566.                 else
  1567.                     restore_write_log=YES
  1568.                 fi
  1569.                 Configuration_changed=YES
  1570.                 ;;
  1571.  
  1572.             P)    Compression_Menu
  1573.                 ;;
  1574.             V)    if [ "$verify_archive" = "YES" ]
  1575.                 then
  1576.                     verify_archive=NO
  1577.                 else
  1578.                     verify_archive=YES
  1579.                 fi
  1580.                 Configuration_changed=YES
  1581.                 ;;
  1582.             Y)    Archive_Type_Menu
  1583.                 ;;
  1584.             U)    Multivolume_Menu
  1585.                 ;;
  1586.             B)    if [ "$double_buffering" = "YES" ] ; then
  1587.                     double_buffering=NO
  1588.                 else
  1589.                     double_buffering=YES
  1590.                 fi
  1591.                 Configuration_changed=YES
  1592.                 ;;
  1593.             S)    $DIALOG   --inputbox "Please specify memory size for double buffering.\n(e.g. 4096k, 207152)" \
  1594.                 9 75 2>$TMP/$DIALOGFILE
  1595.                 if [ $? = 0 ] && test -n "`cat $TMP/$DIALOGFILE`"
  1596.                 then
  1597.                     ddbufsize=`cat $TMP/$DIALOGFILE`
  1598.                     if [ $ddbufsize -lt 512 ] 2>/dev/null ; then
  1599.                         $ddbufsize=512
  1600.                         Configuration_changed=YES
  1601.                     fi
  1602.                 fi
  1603.                 ;;
  1604.             T)    $DIALOG   --inputbox "Please enter the KBackup directory (default: ~/$KBACKDIRDEFAULT)" \
  1605.                 9 75 2>$TMP/$DIALOGFILE
  1606.                 if [ $? = 0 ] && test -n "`cat $TMP/$DIALOGFILE`"
  1607.                 then
  1608.                     datadir=`cat $TMP/$DIALOGFILE`
  1609.                     Configuration_changed=YES
  1610.                 fi
  1611.                 ;;
  1612.             M)    $DIALOG   --inputbox "Please enter the directory for temporary files:" \
  1613.                 9 75 2>$TMP/$DIALOGFILE
  1614.                 if [ $? = 0 ] && test -n "`cat $TMP/$DIALOGFILE`"
  1615.                 then
  1616.                     tmp=`cat $TMP/$DIALOGFILE`
  1617.                     if [ -d "$tmp" -a -w "$tmp" ]
  1618.                     then
  1619.                         changeTMP "$tmp"
  1620.                         Configuration_changed=YES
  1621.                     else
  1622.                         ErrorBox "Cannot access \"$tmp\" as a directory."
  1623.                     fi
  1624.                 fi
  1625.                 ;;
  1626.             D)    Device_Menu
  1627.                 ;;
  1628.             O)    $DIALOG --title " Online Menu Command " --inputbox "
  1629. Please specify the command for viewing the Online Manual.
  1630. Examples are:
  1631.    less $docdir/manual.asc
  1632.    dialog --textbox $docdir/manual.asc 24 77
  1633.    lynx $docdir/whtml/KBackup.html
  1634.    netscape $docdir/html/KBackup.html
  1635. Current setting: $manual_command" 15 75 2>$TMP/$DIALOGFILE
  1636.                 if [ $? = 0 ]
  1637.                 then
  1638.                     if [ "`cat $TMP/$DIALOGFILE`" != "" ]
  1639.                     then
  1640.                         manual_command=`cat $TMP/$DIALOGFILE`
  1641.                         Configuration_changed=YES
  1642.                     fi
  1643.                 fi
  1644.                 ;;
  1645.             "W")    if [ "$device_type" != "TAPE" ]
  1646.                 then
  1647.                     ErrorBox "This option does only make sense
  1648. when using a tape drive."
  1649.                 else
  1650.                     if [ "$AutoRewind" = "YES" ]
  1651.                     then
  1652.                         AutoRewind=NO
  1653.                     else
  1654.                         AutoRewind=YES
  1655.                         MsgBox "You have activated the Auto-Rewind
  1656. option. 
  1657. Please do not use this if you want 
  1658. to write multiple archives on one 
  1659. tape."
  1660.                     fi
  1661.                     Configuration_changed=YES
  1662.                 fi
  1663.                 ;;
  1664.             "<")    return
  1665.                 ;;
  1666.         esac
  1667.         else
  1668.             return
  1669.         fi
  1670.     done
  1671. }
  1672.  
  1673. Write_Config()
  1674. {
  1675.     Check_Settings
  1676.     $DIALOG   --inputbox "Please specify a unique name for this configuration:\nThe current name is:\n\"$configname\"\nJust press RETURN to keep this name." \
  1677.         13 75 2>$TMP/$DIALOGFILE
  1678.     if [ $? = 0 ] 
  1679.     then
  1680.         oldconfig="$configname"
  1681.         configname=`cat $TMP/$DIALOGFILE`
  1682.         if [ "$configname" = "" ]
  1683.         then
  1684.             configname="$oldconfig"
  1685.         fi
  1686.         if [ -d $datadir/$configname ]
  1687.         then
  1688.             $DIALOG --yesno \
  1689.                 "A configuration named\n$configname\ndoes already exist!\n\nOverwrite it with new settings?" 9 40 
  1690.             if [ $? = 0 ]
  1691.             then
  1692.                 save_config
  1693.                 Configuration_changed=NO
  1694.             else
  1695.                 MsgBox "Write Configuration aborted."
  1696.             fi
  1697.         else
  1698.             save_config
  1699.             Configuration_changed=NO
  1700.         fi
  1701.     fi
  1702. }
  1703. Configuration_Menu()
  1704. {
  1705.     while : ; do
  1706.         $DIALOG   --title " Configuration Menu " --menu "\n\
  1707. Choose \"Configure KBackup\" for options that determine how KBackup
  1708. works; choose \"Set file selection parameters\" for deciding which
  1709. files to include in the backup.
  1710. \nThe current configuration is \"$configname\".\n\
  1711. The current parent directory is \"$parent\"." 21 77 7 \
  1712.             P    "Set parent directory for backup/restore " \
  1713.             F    "Set file selection parameters" \
  1714.             C    "Configure KBackup" \
  1715.             W    "Write a configuration file" \
  1716.             L    "Load a configuration file" \
  1717.             D    "Delete a configuration file"\
  1718.             "<"    "Return to main menu" 2>$TMP/$DIALOGFILE
  1719.         if [ $? = 0 ]
  1720.         then
  1721.         case    `cat $TMP/$DIALOGFILE` in
  1722.             F)    File_Selection_Menu
  1723.                 ;;
  1724.             C)    Config_KBackup_Menu
  1725.                 ;;
  1726.             P)    choose_dir $parent
  1727.                 parent="$choose_dir_result"
  1728.                 Configuration_changed=YES
  1729.                 ;;
  1730.             W)    Write_Config
  1731.                 ;;
  1732.             L)    find "$datadir"/* -type d -prune -printf "%f %Tx\n" |\
  1733.                     $FGREP -v "$KBACKDIRDEFAULT" | sort >$TMP/$TMPFILE
  1734.                 lines=`$WC -l <$TMP/$TMPFILE`
  1735.                 if [ "$lines" -gt 15 ] ; then lines=15 ; fi
  1736.                 $DIALOG   --menu "Choose a configuration:" 22 \
  1737.                 60 $lines `cat $TMP/$TMPFILE` 2>$TMP/$DIALOGFILE
  1738.                 if [ $? = 0 ]
  1739.                 then
  1740.                     . $datadir/`cat $TMP/$DIALOGFILE`/Config
  1741.                     changeTMP "$TMP"
  1742.                     Configuration_changed=YES
  1743.                 fi
  1744.                 ;;
  1745.             D)    find "$datadir"/* -type d -prune -printf "%f %Tx\n" |\
  1746.                     $FGREP -v "$KBACKDIRDEFAULT" | sort >$TMP/$TMPFILE
  1747.                 lines=`$WC -l <$TMP/$TMPFILE`
  1748.                 if [ "$lines" -gt 15 ] ; then lines=15 ; fi
  1749.                 $DIALOG --menu "Choose a configuration to
  1750.                 delete:" 20 60 $lines \
  1751.                     `cat $TMP/$TMPFILE` 2>$TMP/$DIALOGFILE
  1752.                 if [ $? = 0 ]
  1753.                 then
  1754.                     rm -rf $datadir/`cat $TMP/$DIALOGFILE`
  1755.                 fi
  1756.                 ;;
  1757.             "<")    Check_Settings
  1758.                 return
  1759.             ;;
  1760.         esac
  1761.         else
  1762.             Check_Settings
  1763.             return
  1764.         fi
  1765.     done
  1766. }
  1767.  
  1768. Goto_N-th()
  1769. {
  1770.     $DIALOG   --inputbox "Please give the number of the backup to go to:" 9 75 2>$TMP/$DIALOGFILE
  1771.     if [ $? = 0 ]
  1772.     then
  1773.         num=`cat $TMP/$DIALOGFILE`
  1774.         test $num -gt 0 2>/dev/null # is it a positive number?
  1775.         if [ $? != 0 ]
  1776.         then
  1777.             ErrorBox "No valid backup number!"
  1778.             return
  1779.         fi
  1780.         InfoBox "Rewinding tape..." 
  1781.         my_mt -f "$device" rewind 
  1782.         pos=1
  1783.         while [ $pos -lt $num ]
  1784.         do
  1785.                     cat < "$device" >$TMP/$TMPFILE 2>$STDERR # read header
  1786.                     check_error -dev
  1787.                     if [ $? != 0 ]
  1788.                     then
  1789.                             return
  1790.                     else
  1791.                             if read firstline < $TMP/$TMPFILE && [ "$firstline" = "#KBackup" ]
  1792.                             then
  1793.                                     . $TMP/$TMPFILE
  1794.                             else
  1795.                                     ErrorBox "No valid KBackup Archive Header.
  1796. Goto failed."
  1797.                                     return
  1798.                             fi
  1799.             fi
  1800.             skip=`expr $backup_filesperarchive - 1`
  1801.             InfoBox "Skipping backup #$pos..."
  1802.             my_mt -f "$device" fsf $skip 
  1803.             pos=`expr $pos + 1`
  1804.         done
  1805.     fi
  1806. }
  1807.  
  1808.  
  1809. Tape_Operation_Menu()
  1810. {
  1811.     if [ "$device_type" != "TAPE" ] ; then
  1812.         ErrorBox \
  1813. "You can only perform these operations on a device
  1814. that is a tape drive, not on an archive file or 
  1815. floppy drive!"
  1816.         return
  1817.     fi
  1818.     
  1819.     while :
  1820.     do
  1821.     $DIALOG   --title " Operations on Tape Drives " --menu \
  1822. "
  1823. This menu is a frontend to the mt(1) command
  1824. for executing tape drive specific operations.
  1825. " 19 51 8\
  1826.         R    "Rewind tape" \
  1827.         D    "Reset tape driver (QIC02 driver only)" \
  1828.         G    "Go to n-th backup on tape" \
  1829.         N    "Go to end of written data"\
  1830.         E    "Erase tape" \
  1831.         T    "Retension tape" \
  1832.         O    "Set tape offline: rewind and unload it"\
  1833.         "<"    "Return to Actions Menu" 2>$TMP/$DIALOGFILE
  1834.     if [ $? = 0 ]
  1835.     then
  1836.         case `cat $TMP/$DIALOGFILE` in
  1837.             R)    InfoBox "Rewinding tape..." 
  1838.                 my_mt -f "$device" rewind 
  1839.                 ;;
  1840.             D)    InfoBox "Resetting tape driver..." 
  1841.                 cat <"$resetdevice" 2>/dev/null
  1842.                 ;;
  1843.             G)    Goto_N-th
  1844.                 ;;
  1845.             N)    InfoBox "Searching for end of data..." 
  1846.                 my_mt -f "$device" eom # mt-GNU
  1847.                 if [ $? = 1 ]
  1848.                 then
  1849.                     my_mt -f "$device" seod # mt-st
  1850.                 fi
  1851.                 ;;
  1852.             O)    InfoBox "Telling device to go offline..."
  1853.                 my_mt -f "$device" offline 
  1854.                 check_error -dev
  1855.                 ;;
  1856.             E)    beep
  1857.                 $DIALOG   --title " DANGEROUS! " --yesno "
  1858. Do you really want to erase the
  1859. whole tape?
  1860.  
  1861. WARNING: This might take very
  1862. long, especially on DAT drives!
  1863. " 11 40 2>$TMP/$DIALOGFILE
  1864.                 if [ $? = 0 ]
  1865.                 then
  1866.                     InfoBox "Erasing tape..." 
  1867.                     my_mt -f "$device" erase 
  1868.                 fi
  1869.                 ;;
  1870.             T)    InfoBox "Retensioning tape..."
  1871.                 my_mt -f "$device" reten 
  1872.                 auto_rewind
  1873.                 check_error -dev
  1874.                 ;;
  1875.             "<")    return
  1876.                 ;;
  1877.         esac
  1878.     else
  1879.         return
  1880.     fi
  1881.     done
  1882. }
  1883.  
  1884. Actions_Menu()
  1885. {
  1886.     while :
  1887.     do
  1888.     $DIALOG   --title " Actions Menu " --menu "\n\
  1889. Actions, apart from backup and restore,\nthat operate on archives.\n" 18 45 8 \
  1890.         T    "Tape Operation" \
  1891.         V    "Verify backup" \
  1892.         S    "Get backup size" \
  1893.         C    "View archive contents" \
  1894.         L    "View a logfile"\
  1895.         D    "Delete a logfile"\
  1896.         B    "Send a bug report" \
  1897.         "<"    "Return to main menu" 2>$TMP/$DIALOGFILE
  1898.     if [ $? = 0 ]
  1899.     then
  1900.         case `cat $TMP/$DIALOGFILE` in
  1901.             V)    Verify
  1902.                 auto_rewind
  1903.                 ;;
  1904.             C)    View_Contents
  1905.                 auto_rewind
  1906.                 ;;
  1907.             S)    Get_BackupSize
  1908.                 ;;
  1909.             L)    View_Logfile
  1910.                 ;;
  1911.             D)    Delete_Logfile
  1912.                 ;;
  1913.             T)    Tape_Operation_Menu
  1914.                 ;;
  1915.             B)    echo -e "Subject: KBackup $VERSION bug report\n(Please fill in the form below:)\n\
  1916.             
  1917. Problem description:\n\n\n\
  1918. -------------------------- KBackup configuration: -------------------------\n\
  1919. " >$TMP/$MAILFILE
  1920.  
  1921.                 write_settings >>$TMP/$MAILFILE
  1922.                 echo -e "
  1923. -------------------------- System information: ----------------------------\n\
  1924. " >>$TMP/$MAILFILE
  1925.                 uname -a >>$TMP/$MAILFILE
  1926.                 cat /proc/devices >>$TMP/$MAILFILE
  1927.                 $EDITOR $TMP/$MAILFILE
  1928.                 while :
  1929.                 do
  1930.                     $DIALOG --title " Bug Report " --menu "" 10 50 3 \
  1931.                     "M"    "Mail bug report to author"\
  1932.                     "S"    "Save bug report in a file" \
  1933.                     "<"    "Back to Actions Menu" 2>$TMP/$DIALOGFILE
  1934.                     if [ $? != 0 ]
  1935.                     then
  1936.                         return    # sigint
  1937.                     fi
  1938.                     case `cat $TMP/$DIALOGFILE` in
  1939.                     "M")    $MAIL $MAILADDRESS <$TMP/$TMPFILE
  1940.                         if [ $? != 0 ]
  1941.                         then
  1942.                             ErrorBox "Could not send bugreport.\n($MAIL missing?) "
  1943.                         else
  1944.                             MsgBox "Bugreport sent."
  1945.                         fi
  1946.                         ;;
  1947.                     "S")     $DIALOG --title " Bug Report "  --inputbox \
  1948.                         "Filename to write to:" 9 75 2>$TMP/$DIALOGFILE 
  1949.                         if [ $? = 0 ] && [ -n `cat $TMP/$DIALOGFILE` ]
  1950.                         then
  1951.                             cat $TMP/$MAILFILE > `cat $TMP/$DIALOGFILE`
  1952.                         fi
  1953.                         ;;
  1954.                     "<")    break
  1955.                         ;;
  1956.                     esac
  1957.                 done
  1958.                 ;;
  1959.             "<")    return
  1960.                 ;;
  1961.         esac
  1962.     else
  1963.         return
  1964.     fi
  1965.     done
  1966. }
  1967.  
  1968. view_manual()
  1969. {
  1970.     $manual_command
  1971.     if [ "$?" != 0 -a "$?" != 255 ]
  1972.     then
  1973.         ErrorBox "Cannot access online manual via \n\"$manual_command\""
  1974.     fi
  1975. }
  1976.  
  1977. #
  1978. # check whether anything is necessary in case CTRL-C was pressed
  1979. #
  1980. main_level_cleanup()
  1981. {
  1982.     if [ "$device_type" = "BLOCKDEV" ]
  1983.     then
  1984.         InfoBox "Trying to unmount device..."
  1985.         umount "$MOUNTPOINT" 2>/dev/null
  1986.     fi
  1987. }
  1988.  
  1989.  
  1990. ############################## MAIN MENU ###########################
  1991.  
  1992. Main_Menu()
  1993. {
  1994.     while : ; do
  1995.     $DIALOG   --title " KBackup $VERSION -- Main Menu " \
  1996.     --menu "\nThe current configuration is:\n$configname" 17 35 7 \
  1997.         C    "Configuration" \
  1998.         B    "Backup" \
  1999.         R    "Restore" \
  2000.         A    "Other Actions" \
  2001.         S    "Scheduling menu"\
  2002.         H    "Help -- view online manual" \
  2003.         X    "Exit"    2>$TMP/$DIALOGFILE
  2004.     if [ $? = 0 ]
  2005.     then
  2006.         case `cat $TMP/$DIALOGFILE` in
  2007.             C)    Configuration_Menu
  2008.                 check_config_changed
  2009.                 ;;
  2010.             A)    Actions_Menu
  2011.                 ;;
  2012.             B)    Backup
  2013.                 main_level_cleanup
  2014.                 auto_rewind
  2015.                 ;;
  2016.             R)    Restore
  2017.                 main_level_cleanup
  2018.                 auto_rewind
  2019.                 ;;
  2020.             S)    do_schedule
  2021.                 check_config_changed
  2022.                 ;;
  2023.             H)    view_manual
  2024.                 ;;
  2025.             X)    check_config_changed
  2026.                 cleanup
  2027.                 clear
  2028.                 reset
  2029.                 return    
  2030.                 ;;
  2031.         esac
  2032.     else
  2033.         return
  2034.     fi
  2035.     done
  2036. }
  2037.  
  2038.  
  2039. ################# OPTIONS PROCESSING ######################
  2040.  
  2041. nargs="$#"
  2042. while [ "$nargs" -gt 0 ] 
  2043. do
  2044.     opt=$1
  2045.     case $opt in
  2046.         "--ttymode")
  2047.             shift
  2048.             TTYMODE=YES
  2049.             nargs=`expr $nargs - 1`
  2050.             ;;
  2051.         "--scheduled-restore")
  2052.             shift
  2053.             schedulename="$1"
  2054.             shift
  2055.             configname="$schedulename"
  2056.             Init
  2057.             scheduled=YES
  2058.             Restore
  2059.             unschedule
  2060.             exit
  2061.             ;;
  2062.         "--scheduled-backup")
  2063.             shift
  2064.             schedulename="$1"
  2065.             shift
  2066.             configname="$schedulename"
  2067.             Init
  2068.             a="$configname"
  2069.             configname=KKK
  2070.             save_config
  2071.             configname="$a"
  2072.             scheduled=YES
  2073.             Backup
  2074.             unschedule
  2075.             exit
  2076.             ;;
  2077.         *)    echo Unknown argument: $opt
  2078.             exit
  2079.             ;;
  2080.     esac
  2081. done
  2082.  
  2083.  
  2084. Init
  2085.  
  2086. clear
  2087.  
  2088. $DIALOG   --title "Welcome to KBackup" --msgbox \
  2089. "     #    #  ######
  2090.      #   #   #     #    ##     ####   #    #  #    #  #####
  2091.      #  #    #     #   #  #   #    #  #   #   #    #  #    #
  2092.      ###     ######   #    #  #       ####    #    #  #    #
  2093.      #  #    #     #  ######  #       #  #    #    #  #####
  2094.      #   #   #     #  #    #  #    #  #   #   #    #  #
  2095.      #    #  ######   #    #   ####   #    #   ####   #
  2096.  
  2097.      Version $VERSION   
  2098.  
  2099.    Copyright (c) 1995, 1996 Karsten Ballueder, Karlsruhe, Germany
  2100.    All rights reserved.
  2101.  
  2102.     (Karsten.Ballueder@stud.uni-karlsruhe.de)
  2103.     http://www.uni-karlsruhe.de/~Karsten.Ballueder/
  2104.     Karsten Ballueder, Lessingstrasse 2, 32756 Detmold, Germany
  2105.                      
  2106.  If you use KBackup, please don't forget to send me a postcard!
  2107.  For the license and conditions of use, see the file COPYING or
  2108.  the manual." 24 70
  2109.  
  2110. trap "echo \"SIGINT caught, trying to leave subroutine...\" >&2 ; return 128 " SIGINT
  2111. Main_Menu
  2112.  
  2113. cleanup
  2114.  
  2115.